<template>
  <div class="score">
    <div
      class="link"
      @click="
        standard.show = true;
        searchHandle();
      "
      v-if="user.type == 0 || user.type == 1"
    >
      {{ score }}
    </div>
    <div v-else>{{ score }}</div>

    <!-- 显示标准分数列表 -->
    <el-dialog title="标准分数列表" :visible.sync="standard.show" width="1000px" class="standard">
      <div class="body">
        <el-table ref="selects" :data="standard.list" border :show-summary="true">
          <el-table-column label="排名" type="index"></el-table-column>
          <el-table-column label="标准名称" prop="title"></el-table-column>
          <el-table-column label="问题数量" prop="issue_sum_before"></el-table-column>
          <el-table-column label="已整改" prop="issue_sum_after"></el-table-column>
          <el-table-column label="已整改未通过" prop="issue_sum_after_no_pass"></el-table-column>
          <el-table-column label="总分" prop="score"></el-table-column>
          <el-table-column label="扣分" prop="before_score"></el-table-column>
          <el-table-column label="得分" prop="after_score"> </el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button size="small" @click="setScore(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer after">
        <div class="left after">
          <p>
            总整改得分 :
            <span>{{ item.score.new }}</span>
          </p>
        </div>
        <el-button @click="standard.show = false" size="small">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: ["score", "item"],
  data() {
    return {
      standard: {
        list: [],
        show: false,
      },
      user: this.$store.state.user,
      afterScore: 0,
    };
  },
  methods: {
    // 计算总分
    afterSumScore() {
      let list = this.standard.list,
        sum = 0;
      for (let i in list) {
        sum = sum + list[i].score;
      }
      this.afterScore = sum;
    },
    // 设置标准扣分
    setScore(item) {
      this.$prompt("请输入扣分,默认 0", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern: /^\d+(\.\d+)?$/,
        inputValidator: function (value) {
          value = parseFloat(value);
          if (value > item.score) {
            return "分数已超,请检查,最高分为 : " + item.score;
          }
        },
        inputErrorMessage: "只能输入整数或小数",
      }).then(({ value }) => {
        value = parseFloat(value);
        // 整改前
        item.before_score = value;
        var data = { ...item };
        data.T = "choose_standard";
        this.axios.post("/admin/Index/handle", data).then((res) => {
          var res = res.data;
          if (res.state) {
            this.common.message({ message: res.info });
            this.searchHandle();
          } else {
            this.common.message({ message: res.info, type: "error" });
          }
        });
      });
    },
    searchHandle() {
      var data = {
        id: this.item.id,
      };
      this.axios.post("/admin/Index/search_standard_score", data).then((res) => {
        var res = res.data;
        if (res.state) {
          this.standard.list = res.other.data;
          // 计算总整改得分
          this.afterSumScore();
        } else {
          this.common.message({ message: res.info, type: "error" });
        }
      });
    },
  },
};
</script>
<style scoped>
.standard >>> .el-dialog__body {
  padding: 0 !important;
}
.standard >>> .el-dialog__footer {
  padding-bottom: 10px;
}
/* 修改分数 */
.edit-score {
  cursor: pointer;
  margin-left: 10px;
  line-height: 33px;
}
.dialog-footer .left p {
  font-size: 16px;
  font-weight: bold;
  float: left;
  margin: 0;
  line-height: 33px;
}
.dialog-footer .left p span {
  color: #f40;
  font-size: 16px;
  font-weight: bold;
  margin-right: 20px;
}
</style>